﻿using System;
using System.Collections.Generic;
using KKSG;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000B7F RID: 2943
	internal class heromvp
	{
		// Token: 0x0600A958 RID: 43352 RVA: 0x001E21F0 File Offset: 0x001E03F0
		public static bool Do(List<XActor> actors)
		{
			bool flag = !heromvp._started;
			if (flag)
			{
				heromvp._started = true;
				heromvp.Start();
			}
			else
			{
				bool flag2 = !XSingleton<XCutScene>.singleton.IsPlaying;
				if (flag2)
				{
					heromvp._started = false;
					heromvp.End();
				}
			}
			return true;
		}

		// Token: 0x0600A959 RID: 43353 RVA: 0x001E2240 File Offset: 0x001E0440
		private static void Start()
		{
			DlgBase<HeroBattleMVPDlg, HeroBattleMVPBehaviour>.singleton.SetVisible(true, true);
			XHeroBattleDocument specificDocument = XDocuments.GetSpecificDocument<XHeroBattleDocument>(XHeroBattleDocument.uuID);
			HeroBattleMapCenter.RowData bySceneID = specificDocument.HeroBattleMapReader.GetBySceneID(XSingleton<XScene>.singleton.SceneID);
			Vector3 one = Vector3.one;
			float angle = 0f;
			bool flag = bySceneID != null && bySceneID.MVPPos.Length >= 4;
			if (flag)
			{
				one = new Vector3(bySceneID.MVPPos[0], bySceneID.MVPPos[1], bySceneID.MVPPos[2]);
				//one..ctor(bySceneID.MVPPos[0], bySceneID.MVPPos[1], bySceneID.MVPPos[2]);
				angle = bySceneID.MVPPos[3];
			}
			heromvp._pos = one;
			heromvp._pos.y = XSingleton<XScene>.singleton.TerrainY(heromvp._pos);
			XLevelRewardDocument specificDocument2 = XDocuments.GetSpecificDocument<XLevelRewardDocument>(XLevelRewardDocument.uuID);
			XLevelRewardDocument.HeroBattleData heroBattleData = (XSingleton<XScene>.singleton.SceneType == SceneType.SCENE_HEROBATTLE) ? specificDocument2.HeroData : specificDocument2.MobaData;
			OverWatchTable.RowData byHeroID = specificDocument.OverWatchReader.GetByHeroID(heroBattleData.MvpHeroID);
			bool flag2 = byHeroID == null;
			if (flag2)
			{
				XSingleton<XDebug>.singleton.AddErrorLog("MvpHeroID error! ID = ", heroBattleData.MvpHeroID.ToString(), null, null, null, null);
			}
			else
			{
				uint presentID = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(byHeroID.StatisticsID[0]).PresentID;
				XEntityPresentation.RowData byPresentID = XSingleton<XEntityMgr>.singleton.EntityInfo.GetByPresentID(presentID);
				bool flag3 = byPresentID == null;
				if (flag3)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("MvpHeroID error! ID = ", presentID.ToString(), null, null, null, null);
				}
				else
				{
					string str = "Animation/" + byPresentID.AnimLocation;
					heromvp._actor = new XActor("Prefabs/" + byPresentID.Prefab, heromvp._pos, XSingleton<XCommon>.singleton.FloatToQuaternion(angle), str + byHeroID.CutSceneAniamtion);
					heromvp._actor.Initilize(0);
					heromvp._actor.GetCurrentAnimLength(new OverrideAnimCallback(heromvp.AnimLoadCallback));
				}
			}
		}

		// Token: 0x0600A95A RID: 43354 RVA: 0x001E2428 File Offset: 0x001E0628
		private static void AnimLoadCallback(XAnimationClip clip)
		{
			float num = (clip != null) ? clip.length : 0f;
			bool flag = num > 0f;
			if (flag)
			{
				heromvp._token = XSingleton<XTimerMgr>.singleton.SetTimer(num, new XTimerMgr.ElapsedEventHandler(heromvp.Idled), null);
			}
			else
			{
				heromvp.Idled(null);
			}
		}

		// Token: 0x0600A95B RID: 43355 RVA: 0x001E2480 File Offset: 0x001E0680
		private static void Idled(object o)
		{
			bool flag = heromvp._actor != null;
			if (flag)
			{
				XHeroBattleDocument specificDocument = XDocuments.GetSpecificDocument<XHeroBattleDocument>(XHeroBattleDocument.uuID);
				XLevelRewardDocument specificDocument2 = XDocuments.GetSpecificDocument<XLevelRewardDocument>(XLevelRewardDocument.uuID);
				XLevelRewardDocument.HeroBattleData heroBattleData = (XSingleton<XScene>.singleton.SceneType == SceneType.SCENE_HEROBATTLE) ? specificDocument2.HeroData : specificDocument2.MobaData;
				OverWatchTable.RowData byHeroID = specificDocument.OverWatchReader.GetByHeroID(heroBattleData.MvpHeroID);
				bool flag2 = byHeroID == null;
				if (flag2)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("MvpHeroID error! ID = ", heroBattleData.MvpHeroID.ToString(), null, null, null, null);
				}
				else
				{
					uint presentID = XSingleton<XEntityMgr>.singleton.EntityStatistics.GetByID(byHeroID.StatisticsID[0]).PresentID;
					XEntityPresentation.RowData byPresentID = XSingleton<XEntityMgr>.singleton.EntityInfo.GetByPresentID(presentID);
					bool flag3 = byPresentID == null;
					if (flag3)
					{
						XSingleton<XDebug>.singleton.AddErrorLog("MvpHeroID error! ID = ", presentID.ToString(), null, null, null, null);
					}
					else
					{
						bool flag4 = string.IsNullOrEmpty(byHeroID.CutSceneIdleAni);
						if (!flag4)
						{
							string str = "Animation/" + byPresentID.AnimLocation;
							heromvp._actor.OverrideAnim(str + byHeroID.CutSceneIdleAni);
						}
					}
				}
			}
		}

		// Token: 0x0600A95C RID: 43356 RVA: 0x001E25B4 File Offset: 0x001E07B4
		private static void End()
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(heromvp._token);
			DlgBase<HeroBattleMVPDlg, HeroBattleMVPBehaviour>.singleton.SetVisible(false, true);
			bool flag = heromvp._actor != null;
			if (flag)
			{
				heromvp._actor.Uninitilize();
				heromvp._actor = null;
			}
		}

		// Token: 0x04003E9D RID: 16029
		private static uint _token = 0U;

		// Token: 0x04003E9E RID: 16030
		private static XActor _actor = null;

		// Token: 0x04003E9F RID: 16031
		private static bool _started = false;

		// Token: 0x04003EA0 RID: 16032
		private static Vector3 _pos = Vector3.zero;
	}
}
